<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@include file="../common/head.jsp" %>

<script src="../js/jquery-3.3.1.min.js"></script>
<script>

    function checkUserCode(userCodeObject) {
        var flag = false;
        var msg = "请输入用户编码";
        if (userCodeObject.value != '') {
            msg = "";
            $.ajax({
                type: "post", // 指定客户端向服务器端发送数据的方式
                url: "user/showUserCount", // 向服务器请求的地址
                data: {// 向服务器发送的数据
                    "userCode": userCodeObject.value
                },
                async: false,// 是否为同步,true(默认值):异步 false:同步
                success: function (data) {// 服务器成功给予客户端响应的数据 out.print();
                    msg = "可用";
                    if (data != '0') {
                        msg = "此编码已存在,不可用"
                    } else {
                        flag = true;
                    }
                }

            });
        }
        userCodeObject.nextElementSibling.innerText = msg;
        return flag;
    }

    function checkDate() {
        var result = checkUserCode($("#userCode").get(0));
        return result;
    }
</script>
<div class="right">
    <div class="location">
        <strong>你现在所在的位置是:</strong>
        <span>用户管理页面 >> 用户添加页面</span>
    </div>
    <div class="providerAdd">
        <form id="userForm" method="post" action="user/doAdd" onsubmit="return checkDate()">
            <!--div的class 为error是验证错误，ok是验证成功-->
            <div>
                <label for="userCode">用户编码：</label>
                <input type="text" name="userCode" id="userCode" onblur="checkUserCode(this)">
                <!-- 放置提示信息 -->
                <font color="red"></font>
            </div>
            <div>
                <label for="userName">用户名：</label>
                <input type="text" name="userName" id="userName" value="">
                <font color="red"></font>
            </div>
            <div>
                <label for="userPassword">用户密码：</label>
                <input type="password" name="userPassword" id="userPassword" value="">
                <font color="red"></font>
            </div>
            <div>
                <label for="userPassword">确认密码：</label>
                <input type="password" name="userPassword" id="ruserPassword" value="">
                <font color="red"></font>
            </div>
            <div>
                <label>用户性别：</label>
                <select name="gender" id="gender">
                    <option value="1" selected="selected">男</option>
                    <option value="2">女</option>
                </select>
            </div>
            <div>
                <label for="birthday">出生日期：</label>
                <input type="text" Class="Wdate" id="birthday" name="birthday"/>
                <font color="red"></font>
            </div>
            <div>
                <label for="phone">用户电话：</label>
                <input type="text" name="phone" id="phone" value="">
                <font color="red"></font>
            </div>
            <div>
                <label for="address">用户地址：</label>
                <input name="address" id="address" value="">
            </div>
            <div>
                <label>用户角色：</label>
                <!-- 列出所有的角色分类 -->
                <select name="role.roleId" id="userRole">
                    <c:forEach items="${requestScope.roleList}" var="role">
                        <option value="${role.roleId}">${role.roleName}</option>
                    </c:forEach>
                </select>

                <font color="red"></font>
            </div>
            <div class="providerAddBtn">
                <input type="submit" name="add" id="add" value="保存">
                <input type="button" onclick="window.location.back()" id="back" name="back" value="返回">
            </div>
        </form>
    </div>
</div>
</section>
<%@include file="../common/foot.jsp" %>
